<?php
/**
 * LICENSE
 * 
 * [license information]
 * 
 * @category   BKPay
 * @copyright  Copyright (c) 2011 bkpay.vn
 * @license    http://license.bkpay.vn
 * @version    v 1.0 2011-09-19
 * @author	   hoaihuong@9webdesigns.com, s50702790@gmail.com
 */
require_once 'modules/transaction/models/Transaction.php';
require_once 'modules/user/models/Wallet.php';
require_once 'modules/bkcard/models/BKCard.php';
require_once 'modules/mail/models/Mail.php';
require_once 'modules/sms/models/SMS.php';
require_once 'modules/user/models/User.php';

require_once 'libs/BKPay/Function.php';
require_once 'libs/BKPay/Constant.php';

require_once 'services/classes/MakePaymentRequest.php';
require_once 'services/classes/MakePaymentResponse.php';
require_once 'services/classes/ExecutePaymentRequest.php';
require_once 'services/classes/ExecutePaymentResponse.php';
require_once 'services/classes/FinishPaymentRequest.php';
require_once 'services/classes/FinishPaymentResponse.php';
require_once 'services/classes/RechargePaymentRequest.php';
require_once 'services/classes/RechargePaymentResponse.php';
require_once 'services/classes/AuthenPaymentRequest.php';
require_once 'services/classes/AuthenPaymentResponse.php';
require_once 'services/classes/TransferPaymentRequest.php';
require_once 'services/classes/TransferPaymentResponse.php';

require_once 'Zend/Log/Writer/Stream.php';
require_once 'Zend/Log/Formatter/Xml.php';
require_once 'Zend/Log.php';

class PayService {
	
//	public $authentication = false;
//	
//	public function security($api, $code)
//	{
//		if ('bkpay' == $api->enc_value && '5BSDrajYf6' == $code->enc_value ) {
//			$this->authentication = true;
////			return true;
//		}
//		else {
////			return false;
//		}
//		
//	}
	
	/**
	 * Request register transaction.
	 * 
	 * @param  MakePaymentRequest $request
	 * @return MakePaymentResponse $response
	 */
	public function makePayment( $request ) {
		
		/**
   		 * Created response
   		 */
   		$response = new MakePaymentResponse();
   		
   		/**
   		 * Logging
   		 */
//   		$transactionFile = 'log/transaction_' . date('d_m_Y',time()) . '.txt';
//   		$writer = new Zend_Log_Writer_Stream($transactionFile);
   		
   		if (null == $request) {
   			/**
   			 * No request parameter, response fail
   			 */
   			$response->actionType = BKPay_Constant::CREATED;
   			$response->ack = BKPay_Constant::ERROR;
   			$response->paymentInfo = Nine_Language::translate("Make payment is unsuccessful!");
   		}
   		else {
   			if ($request->actionType == BKPay_Constant::CREATE) {
   				/**
   				 * Generation token
   				 */
   				$tokenID = BKPay_Function::generateToken();
   				
   				/**
   				 * Save token in session
   				 */
   				$session = Nine_Registry::getSession();
   				$session->tokenID = $tokenID;
   				
   				/**
   				 * Assign to response
   				 */
   				
   				$response->actionType = BKPay_Constant::CREATED;
   				$response->ack = BKPay_Constant::SUCCESS;
   				$response->tokenID = $tokenID;
   				$response->paymentInfo = Nine_Language::translate("Make payment is successful!");
   				
//		   		$logger = new Zend_Log($writer);
//		    	$logger->info('System have received request make payment from userID: ' . Nine_Registry::getLoggedInUserId(),Zend_Log::INFO);
   			}
   			else {
   				$response->actionType = BKPay_Constant::CREATED;
   				$response->ack = BKPay_Constant::ERROR;
   				$response->paymentInfo = Nine_Language::translate("Payment is not valid. Please try again!");
   			}
   		}
   		
   		/**
   		 * Return response
   		 */
   		return $response;
	}
	/**
	 * Request execute transaction.
	 * 
	 * @param ExecutePaymentRequest $request
	 * @return ExecutePaymentResponse $reponse
	 */
	public function executePayment( $request ) {
		/**
   		 * Created response
   		 */
   		$response = new ExecutePaymentResponse();
   		
   		if (null == $request) {
   			/**
   			 * No request parameter, response fail
   			 */
   			$response->actionType = BKPay_Constant::EXECUTED;
   			$response->ack = BKPay_Constant::ERROR;
   			$response->paymentInfo = Nine_Language::translate("Execute payment is unsuccessful!");
   			
   		}
   		else {
   			$session = Nine_Registry::getSession();
   			if ($request->actionType == BKPay_Constant::EXECUTE && $request->tokenID == $session->tokenID) {
   				
   				/**
   				 * Check minimum balance from user
   				 */
   				$objWallet = new Models_Wallet();
   				if (false != @$objWallet->checkMinimumBalance($request->fromUserID, $request->amount)) {
   					
	   				$objTransaction = new Models_Transaction();
	   				
	   				/**
	   				 * Generation activationCode
	   				 */
	   				$activationCode = BKPay_Function::generateActivationCode();
	   				
	   				/**
	   				 * Preparation transaction
	   				 */
	   				$newTransaction = array(
	   									'from_user_id' => @$request->fromUserID,
	   									'to_user_id' => @$request->toUserID,
										'type' => 0,	
	   									'bill_id'=> @$request->billID,
	   									'title'=> @$request->title,
	   									'description'=> @$request->description,
	   									'number'=> @$request->number,
	   									'unit'=> @$request->unit,
	   									'amount' => @$request->amount,
	   									'note' => @$request->note,
	   									'created_date' => time(),
	   									'activation_code'=> $activationCode,
	   									'approved' => 0,
	   									);
	   				
	   				try {
	   					/**
		   				 * Insert transaction
		   				 */					
	   					$transactionID = $objTransaction->insert($newTransaction);	
	   					
	   					$response->actionType = BKPay_Constant::EXECUTED;
	   					$response->ack = BKPay_Constant::SUCCESS;
	   					$response->transactionID = $transactionID;
	   					$response->activationCode = $activationCode;
	   					$response->paymentInfo = Nine_Language::translate("Execute payment is successful!");
	   					
	   					/**
						 * Send authentication code to email, sms
						 */
	   					
	   					$objUser = new Models_User();
						$objMail = new Models_Mail();
						$objSMS = new Models_SMS();
						
						$fromUser =  $objUser->getUserWithConsumerProfile($request->fromUserID);
						
						$mailValues = array(
				                    	'full_name'	=>	$fromUser['full_name'],
				                    	'timestamp'	=>	date('H:i:s A d-m-Y',time()),
				                    	'transactionID'	=>	$transactionID,
				                    	'activationCode' => $activationCode
				                    );
				        $objMail->sendHtmlMail('send_transaction_activationcode',$mailValues,$fromUser['email']);
						
				        $smsContent = 'Ma xac thuc giao dich cua ban la: ' . $activationCode;
				        
				        $newSMS = array(
				        			'telephone_no' => $fromUser['telephone_no'],
				        			'content' => $smsContent,
				        			'created_date' => time(),
				        			'is_sent' => 0
				        			);
						$objSMS->insert($newSMS);
//				    	/**
//				   		 * Logging
//				   		 */
//				   		$transactionFile = 'log/transaction_' . date('d_m_Y',time()) . '.txt';
//				   		$writer = new Zend_Log_Writer_Stream($transactionFile);
//				   		$logger = new Zend_Log($writer);
//				   		
//				   		$logger->log("Begin execute transaction");
//				   		
//				    	$loggedInfo = 'System have executed request execute payment from userID: ' . "{$request->fromUserID}" . ' with below information:';
//				    	$tmp = $newTransaction;
//				    	unset($tmp['activation_code']);
//				    	foreach ($tmp as $key=>$value) {
//				    		$loggedInfo.= " " . strtoupper($key) . ': ' . "{$value}"; 
//				    	}
//				    	
//				    	$logger->info($loggedInfo);
				   					
	   					
	   				} catch (Exception $e) {
	   					$response->actionType = BKPay_Constant::EXECUTED;
	   					$response->ack = BKPay_Constant::ERROR;
	   					$response->paymentInfo = Nine_Language::translate("Execute payment is processing error!");
	   					
	   				}	
   				}
   				else {
   					$response->actionType = BKPay_Constant::EXECUTED;
   					$response->ack = BKPay_Constant::ERROR;
   					$response->paymentInfo = Nine_Language::translate("Wallet is not valid OR you don't have enought money to execute payment. Please try again!");
   					
   				}							
   			}
   			else {
   				$response->actionType = BKPay_Constant::EXECUTED;
   				$response->ack = BKPay_Constant::ERROR;
   				$response->paymentInfo = Nine_Language::translate("Payment is not valid. Please try again!");
   			}
   		}
   		
   		/**
   		 * Return response
   		 */
   		return $response;
	}
	
	/**
	 * Request finish transaction.
	 * 
	 * @param FinishPaymentRequest $request
	 * @return FinishPaymentResponse $reponse
	 */
	public function finishPayment ($request) {
		
		/**
   		 * Created response
   		 */
   		$response = new FinishPaymentResponse();
   		
   		if (null == $request) {
   			/**
   			 * No request parameter, response fail
   			 */
   			$response->actionType = BKPay_Constant::FINISHED;
   			$response->ack = BKPay_Constant::ERROR;
   			$response->paymentInfo = Nine_Language::translate("Finish payment is unsuccessful!");
   			
   		}
   		else {
   			
   			$objTransaction = new Models_Transaction();
   			
   			if (null != @$request->transactionID) {
   				/**
   				 * Get transaction
   				 */
   				$transaction = $objTransaction->getTransactionById($request->transactionID);
   				
   				/**
   				 * Authentication
   				 */
   				if (@$request->actionType == "FINISH" && @$request->activationCode == $transaction->activation_code && 0 == $transaction->approved) {
   					
   					try {
	   					/**
	   					 * Approved transaction
	   					 */
	   					$transaction->approved = 1;
	   					$transaction->save();
	   					
	   					/**
	   					 * Transfer wallet
	   					 */
	   					$objWallet = new Models_Wallet();
	   					
	   					$fromWallet = $objWallet->getWalletByUserId($transaction->from_user_id);
	   					$fromWallet->value = $fromWallet->value - $transaction->amount;
	   					$fromWallet->save();
	   					
	   					$toWallet = $objWallet->getWalletByUserId($transaction->to_user_id);
	   					$toWallet->value = $toWallet->value + $transaction->amount;
	   					$toWallet->save();

	   					$response->actionType = BKPay_Constant::FINISHED;
	   					$response->ack = BKPay_Constant::SUCCESS;
	   					$response->transactionID = $request->transactionID;
	   					$response->paymentInfo = Nine_Language::translate("Finish payment is successful!");
	   					
	   					/**
						 * Send mail,sms finish transaction
						 */
						$objMail = new Models_Mail();
						$objUser = new Models_User();
				        $objSMS = new Models_SMS();
				        
				        $fromUser = @$objUser->getUserWithConsumerProfile($transaction->from_user_id);
				        $toUser = @$objUser->getUserWithMerchantProfile($transaction->to_user_id);
				        
//				        $response->paymentInfo = $toUser['email'];
				      	
//				        return $response;
				        
				        /**
				         * Send email,sms to from user
				         */
						$mailValues = array(
				                    	'full_name'	=>	@$fromUser['full_name'],
				                    	'timestamp'	=>	@$response->timestamp,
				                    	'transactionID'	=>	@$response->transactionID,
										'amount'	=> @$transaction->amount
				                    );
				        $objMail->sendHtmlMail('finish_transaction',$mailValues,$fromUser['email']);
				        
				        $newSMS = array(
				        			'telephone_no' => @$fromUser['telephone_no'],
				        			'content' => @$response->paymentInfo,
				        			'created_date' => time(),
				        			'is_sent' => 0
				        			);
						$objSMS->insert($newSMS);
				        
				        /**
				         * Send email, to toUser
				         */
				        $mailValues = array(
				        				'from_user' => @$fromUser['full_name'],
				                    	'to_user'	=>	@$toUser['full_name'],
				                    	'timestamp'	=>	@$response->timestamp,
				                    	'transactionID'	=>	@$response->transactionID,
				        				'amount'	=> @$transaction->amount
				                    );
				        $objMail->sendHtmlMail('finish_transaction_touser',$mailValues,$toUser['email']);
				       
//				    	$loggedInfo = 'System have finished request execute payment from userID: ' . "{$transaction->from_user_id}" . ' with below information:';
//				    	
//				    	$tmp = $transaction->toArray();
//				    	unset($tmp['activation_code']);
//				       	foreach ($tmp as $key=>$value) {
//				    		$loggedInfo.= " " . strtoupper($key) . ': ' . "{$value}"; 
//				    	}
//				    	
//				    	$logger->info($loggedInfo);
				    	
   					} catch (Exception $e) {
   						$response->actionType = BKPay_Constant::FINISHED;
	   					$response->ack = BKPay_Constant::ERROR;
	   					$response->paymentInfo = Nine_Language::translate("Finish payment is processing error!");
	   					
//	   					$logger->log($response->paymentInfo);
   					}
   				}
   				else {
   					$response->actionType = BKPay_Constant::FINISHED;
   					$response->ack = BKPay_Constant::ERROR;
   					$response->transactionID = $request->transactionID;
   					$response->paymentInfo = Nine_Language::translate("Finish payment is processing error!");
   					
//   					$logger->log("Activation Code or FinishPaymentRequest is not valid.");
   					
   				}
   				
   			}
   			else {
   				$response->actionType = BKPay_Constant::FINISHED;
   				$response->ack = BKPay_Constant::ERROR;
   				$response->transactionID = $request->transactionID;
   				$response->paymentInfo = Nine_Language::translate("Payment is not valid. Please try again!");
   				
//   				$logger->log("TransactionID is not valid");
   			}
   			
   		}
   		
   		/**
   		 * Return response
   		 */
   		return $response;
	}
	/**
	 * Recharge money from bank (or card) to account
	 * 
	 * @param RechargePaymentRequest $request
	 * @return RechargePaymentResponse $response
	 */
	public function rechargePayment($request)
	{
		/**
   		 * Created response
   		 */
   		$response = new RechargePaymentResponse();
   		
   		if (null == $request) {
   			/**
   			 * No request parameter, response fail
   			 */
   			$response->actionType = BKPay_Constant::RECHARGED;
   			$response->ack = BKPay_Constant::ERROR;
   			$response->paymentInfo = Nine_Language::translate("Recharge payment is unsuccessful!");
   		}
   		else {
   			if ('RECHARGE' == @$request->actionType && $request->tokenID == Nine_Registry::getSession()->tokenID) {
   				
   				$objWallet = new Models_Wallet();
   				
   				if (null != @$request->userID) {
   					
	   				$wallet = @$objWallet->getWalletByUserId($request->userID);
	   				
	   				if (null != $wallet) {
	   					$objBKCard = new Models_BKCard();
	   					$card = $objBKCard->getBKCardByCode(@$request->code);

	   					if (null != $card && 1 == $card['enabled'] && 0 == $card['purchased']) {
	   						
	   						try {
		   						/**
				   				 * Increase money
				   				 */
				   				$wallet->value += $card['value'];
				   				$wallet->save();
				   				
				   				$objBKCard->update(array('purchased' => 1), array('bkcard_id=?'=>$card['bkcard_id']));
				   				
				   				$objTransaction = new Models_Transaction();
				   				
				   				/**
				   				 * Preparation transaction
				   				 */
				   				$newTransaction = array(
				   									'from_user_id' => @$request->userID,
				   									'to_user_id' => @$request->userID,
													'type' => 1,	
				   									'title'=> 'Recharge',
				   									'description'=> 'Recharge payment',
				   									'number' => 1,
				   									'unit' => @$card['value'],
				   									'amount' => @$card['value'],
				   									'created_date' => time(),
				   									'approved' => 1,
				   									);
				   				
			   					/**
				   				 * Insert transaction
				   				 */					
			   					$transactionID = $objTransaction->insert($newTransaction);	
				   				
				   				$response->actionType = BKPay_Constant::RECHARGED;
	   							$response->ack = BKPay_Constant::SUCCESS;
	   							$response->paymentInfo = Nine_Language::translate("Recharge payment request is completed!");
	   							
	   							/**
						   		 * Logging
						   		 */
						   		$transactionFile = 'log/transaction_' . date('d_m_Y',time()) . '.txt';
			   					$writer = new Zend_Log_Writer_Stream($transactionFile);
						   		$logger = new Zend_Log($writer);
						    	
						    	$loggedInfo = 'System have executed request recharge payment from userID: ' . "{$request->userID}" . ' with charge number is: ' . $card['value'];
						    	$logger->info($loggedInfo);
						    	
	   						} catch (Exception $e) {
	   							$response->actionType = BKPay_Constant::RECHARGED;
	   							$response->ack = BKPay_Constant::ERROR;
	   							$response->paymentInfo = Nine_Language::translate("Recharge payment is processing error!");
	   						}
	   					}
	   					else {
	   						$response->actionType = BKPay_Constant::RECHARGED;
   							$response->ack = BKPay_Constant::ERROR;
   							$response->paymentInfo = Nine_Language::translate("Card does not exits or expired !");
	   					}
		   				
	   				}
	   				else {
	   					$response->actionType = BKPay_Constant::RECHARGED;
   						$response->ack = BKPay_Constant::ERROR;
   						$response->paymentInfo = Nine_Language::translate("User does not exits wallet or invalid !");
	   				}
   				}
   				else {
   					$response->actionType = BKPay_Constant::RECHARGED;
   					$response->ack = BKPay_Constant::ERROR;
   					$response->paymentInfo = Nine_Language::translate("User does not exits or invalid !");
   				}
   			}
   		}
   		/**
   		 * Return response
   		 */
   		return $response;
	}
	
	
	/**
	 * Withdrawal money from account to bank (or card)
	 * 
	 * @param array $request
	 * @return array $response
	 */
	public function withdrawPayment($request)
	{
		/**
   		 * Created response
   		 */
   		$response = array();
   		
   		
   		/**
   		 * Return response
   		 */
   		return $response;
	}
	/**
	 * Transfer money from account to other account
	 * 
	 * @param TransferPaymentRequest $request
	 * @return TransferPaymentResponse $response
	 */
	public function transferPayment($request)
	{
		/**
   		 * Created response
   		 */
   		$response = new TransferPaymentResponse();
   		
   		if (null == $request) {
   			/**
   			 * No request parameter, response fail
   			 */
   			$response->actionType = BKPay_Constant::TRANSFERED;
   			$response->ack = BKPay_Constant::ERROR;
   			$response->paymentInfo = Nine_Language::translate("Transfer payment is unsuccessful!");
   		}
   		else {
   			if ('TRANSFER' == @$request->actionType && $request->tokenID == Nine_Registry::getSession()->tokenID) {
   				
   				$objWallet = new Models_Wallet();
   				
   				if (null != @$request->fromUserID && null != @$request->toUserID) {
   					$fromWallet = $objWallet->getWalletByUserId($request->fromUserID);
   					$toWallet = $objWallet->getWalletByUserId($request->toUserID);
   				
	   				if (null != $fromWallet && null != $toWallet && false != $objWallet->checkMinimumBalance($request->fromUserID,$request->amount)) {
   						try {
	   						/**
			   				 * Transfer money
			   				 */
			   				$fromWallet->value = $fromWallet->value - $request->amount;
			   				$fromWallet->save();
			   				
			   				$toWallet->value = $toWallet->value + $request->amount;
			   				$toWallet->save();
				   				
			   				$objTransaction = new Models_Transaction();
				   				
			   				/**
			   				 * Preparation transaction
			   				 */
			   				$newTransaction = array(
			   									'from_user_id' => @$request->fromUserID,
			   									'to_user_id' => @$request->toUserID,
												'type' => 3,	
			   									'title'=> 'Transfer',
			   									'description'=> 'Transfer payment',
			   									'amount' => @$request->amount,
			   									'created_date' => time(),
			   									'approved' => 1,
			   									);
			   				
		   					/**
			   				 * Insert transaction
			   				 */					
		   					$transactionID = $objTransaction->insert($newTransaction);	
				   				
			   				$response->actionType = BKPay_Constant::TRANSFERED;
	   						$response->ack = BKPay_Constant::SUCCESS;
	   						$response->paymentInfo = Nine_Language::translate("Transfer payment request is completed!");
	   							
	   						/**
						   	 * Logging
						   	 */
					   		$transactionFile = 'log/transaction_' . date('d_m_Y',time()) . '.txt';
		   					$writer = new Zend_Log_Writer_Stream($transactionFile);
					   		$logger = new Zend_Log($writer);
					    	
					    	$loggedInfo = 'System have executed request transfer payment from userID: ' . "{$request->toUserID}" . ' with charge number is: ' . $request->amount;
					    	$logger->info($loggedInfo);
   						} catch (Exception $e) {
   							$response->actionType = BKPay_Constant::TRANSFERED;
	   						$response->ack = BKPay_Constant::ERROR;
	   						$response->paymentInfo = Nine_Language::translate("Transfer payment is processing error!");
   						}
   					}
   					else {
   						$response->actionType = BKPay_Constant::TRANSFERED;
   						$response->ack = BKPay_Constant::ERROR;
   						$response->paymentInfo = Nine_Language::translate("Wallet does not exits or invalid !");
	   				}
		   				
	   			}
	   			else {
	   				$response->actionType = BKPay_Constant::TRANSFERED;
   					$response->ack = BKPay_Constant::ERROR;
   					$response->paymentInfo = Nine_Language::translate("User does not exits or invalid !");
	   			}
   			}
   		}
   		/**
   		 * Return response
   		 */
   		return $response;
	}
	
	/**
	 * Authentication unauthen valid transaction
	 * 
	 * @param AuthenPaymentRequest $request
	 * @return AuthenPaymentResponse $response
	 */
	public function authenPayment($request) {
		/**
   		 * Created response
   		 */
   		$response = new AuthenPaymentResponse();
   		if (null == $request) {
   			/**
   			 * No request parameter, response fail
   			 */
   			$response->actionType = BKPay_Constant::FINISHED;
   			$response->ack = BKPay_Constant::ERROR;
   			$response->paymentInfo = Nine_Language::translate("Finish payment is unsuccessful!");
   		}
   		else {
   			$objTransaction = new Models_Transaction();
   			if (null != @$request->transactionID) {
   				/**
   				 * Get transaction
   				 */
   				$transaction = $objTransaction->getTransactionById($request->transactionID);
   				
   				/**
   				 * Authentication
   				 */
   				if (@$request->actionType == "FINISH" && @$request->activationCode == $transaction->activation_code && 0 == $transaction->approved && $request->tokenID == Nine_Registry::getSession()->tokenID) {
   					try {
	   					/**
	   					 * Approved transaction
	   					 */
	   					$transaction->approved = 1;
	   					$transaction->save();
	   					
	   					/**
	   					 * Transfer wallet
	   					 */
	   					$objWallet = new Models_Wallet();
	   					
	   					$fromWallet = $objWallet->getWalletByUserId($transaction->from_user_id);
	   					$fromWallet->value = $fromWallet->value - $transaction->amount;
	   					$fromWallet->save();
	   					
	   					$toWallet = $objWallet->getWalletByUserId($transaction->to_user_id);
	   					$toWallet->value = $toWallet->value + $transaction->amount;
	   					$toWallet->save();
	   					
	   					$response->actionType = BKPay_Constant::FINISHED;
	   					$response->ack = BKPay_Constant::SUCCESS;
	   					$response->transactionID = $request->transactionID;
	   					$response->paymentInfo = Nine_Language::translate("Finish payment is successful!");
	   					
	   					
	   					/**
				   		 * Logging
				   		 */
				   		$transactionFile = 'log/transaction_' . date('d_m_Y',time()) . '.txt';
	   					$writer = new Zend_Log_Writer_Stream($transactionFile);
				   		$logger = new Zend_Log($writer);
				    	
				    	$loggedInfo = 'System have finished request execute payment from userID: ' . "{$transaction->from_user_id}" . ' with below information:';
				    	
				    	$tmp = $transaction->toArray();
				    	unset($tmp['activation_code']);
				       	foreach ($tmp as $key=>$value) {
				    		$loggedInfo.= " " . strtoupper($key) . ': ' . "{$value}"; 
				    	}
				    	
				    	$logger->log($loggedInfo, Zend_Log::INFO);
				    	
   					} catch(Exception $e) {
   						$response->actionType = BKPay_Constant::FINISHED;
	   					$response->ack = BKPay_Constant::ERROR;
	   					$response->paymentInfo = Nine_Language::translate("Finish payment is processing error!");
   					}
   				}
   				else {
   					$response->actionType = BKPay_Constant::FINISHED;
   					$response->ack = BKPay_Constant::ERROR;
   					$response->transactionID = $request->transactionID;
   					$response->paymentInfo = Nine_Language::translate("Finish payment is processing error!");
   				}
   				
   			}
   			else {
   				$response->actionType = BKPay_Constant::FINISHED;
   				$response->ack = BKPay_Constant::ERROR;
   				$response->transactionID = $request->transactionID;
   				$response->paymentInfo = Nine_Language::translate("Payment is not valid. Please try again!");
   			}
   		}
   		
   		/**
   		 * Return response
   		 */
   		return $response;
	}
	
}
